import AJAX from '@/utils/ajax'

class Digg {
  constructor() {
    const that = this
    $('body').on('click', '#up,#down,#flower,#digg', function() {
      that.set($(this), { id: $(this).data('id'), sid: $(this).data('sid'), type: $(this).data('type'), name: $(this).data('name') })
    })
  }
  set(obj, data) {
    AJAX({ url: 'digg', method: 'post', data }).then(res => {
      if (res.code === 1) {
        const count = obj.find('#count').text() * 1 + 1
        obj.find('#count').text(count)
        obj.find('#count').attr('data-count', count)
      }
      layer.msg(res.msg)
    })
  }
}

export default Digg
